from Bio import Entrez, SeqIO
handle = Entrez.esearch(db="nucleotide", retmax=20, term="Opuntia")
record = Entrez.read(handle)
for r in record["IdList"]:
  g = Entrez.efetch(db="nucleotide", id=r , rettype="fasta")
  seq = SeqIO.read(g, "fasta")
  output_handle = open("example.fasta", "w")
  SeqIO.write([seq], output_handle, "fasta")
  output_handle.close()

from Bio.Emboss.Applications import Primer3Commandline
primer_cl = Primer3Commandline()
primer_cl.set_parameter("-sequence", "in.pr3")
primer_cl.set_parameter("-outfile", "out.pr3")
primer_cl.set_parameter("-productsizerange", "350,10000")
primer_cl.set_parameter("-target", "%s,%s" % (start, end))

from Bio.Application import generic_run
result, messages, errors = generic_run(primer_cl)

open_outfile = open("out.pr3", "r")
from Bio.Emboss.Primer import Primer3Parser
parser = Primer3Parser()
primer_record = parser.parse(open_outfile)

open_excelfile = open(excel_file, "w")
primer = primer_record.primers[0]
open_excelfile.write("%s,%s,%s" % (sequence_name, primer.forward_seq, primer.reverse_seq))
